/*
  The MIT License
  
  Copyright (c) 2009 smath project
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:
  
  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
*/
package pl.smath.expression.model;

import junit.framework.TestCase;
import pl.smath.expression.model.Term;
import pl.smath.expression.parser.ExpressionParser;
import pl.smath.expression.parser.ExpressionParserException;


public class TermTestCase extends TestCase {

	public void testTheSameFalse1() throws ExpressionParserException{
		ExpressionParser parser = new ExpressionParser();
			
		Term term1 = parser.parseText( "3" );
		Term term2 = parser.parseText( "2" );
		assertFalse(term1.isAbsTheSame(term2));
	}

	public void testTheSameFalse2() throws ExpressionParserException{
		ExpressionParser parser = new ExpressionParser();
			
		Term term1 = parser.parseText( "x" );
		Term term2 = parser.parseText( "2" );
		assertFalse(term1.isAbsTheSame(term2));
	}

	public void testTheSameFalse3() throws ExpressionParserException{
		ExpressionParser parser = new ExpressionParser();
			
		Term term1 = parser.parseText( "2*x" );
		Term term2 = parser.parseText( "3*x" );
		assertFalse(term1.isAbsTheSame(term2));
	}

	public void testTheSameFalse4() throws ExpressionParserException{
		ExpressionParser parser = new ExpressionParser();
			
		Term term1 = parser.parseText( "x" );
		Term term2 = parser.parseText( "y" );
		assertFalse(term1.isAbsTheSame(term2));
	}

	public void testTheSameFalse5() throws ExpressionParserException{
		ExpressionParser parser = new ExpressionParser();
			
		Term term1 = parser.parseText( "a+1" );
		Term term2 = parser.parseText( "1*a" );
		assertFalse(term1.isAbsTheSame(term2));
	}

	public void testTheSameNumeric() throws ExpressionParserException{
		ExpressionParser parser = new ExpressionParser();
			
		Term term1 = parser.parseText( "2" );
		Term term2 = parser.parseText( "2" );
		assertTrue(term1.isAbsTheSame(term2));
	}

	public void testTheSameSymbol() throws ExpressionParserException{
		ExpressionParser parser = new ExpressionParser();
			
		Term term1 = parser.parseText( "x" );
		Term term2 = parser.parseText( "x" );
		assertTrue(term1.isAbsTheSame(term2));
	}

	public void testTheSameMulti() throws ExpressionParserException{
		ExpressionParser parser = new ExpressionParser();
			
		Term term1 = parser.parseText( "x*y" );
		Term term2 = parser.parseText( "y*x" );
		assertTrue(term1.isAbsTheSame(term2));
	}

	public void testTheSameFraction() throws ExpressionParserException{
		ExpressionParser parser = new ExpressionParser();
			
		Term term1 = parser.parseText( "x/y" );
		Term term2 = parser.parseText( "x/y" );
		assertTrue(term1.isAbsTheSame(term2));
	}

	public void testTheSameExponentiation() throws ExpressionParserException{
		ExpressionParser parser = new ExpressionParser();
			
		Term term1 = parser.parseText( "x^y" );
		Term term2 = parser.parseText( "x^y" );
		assertTrue(term1.isAbsTheSame(term2));
	}

	public void testCopyNumeric() throws ExpressionParserException{
		ExpressionParser parser = new ExpressionParser();
			
		Term term = parser.parseText( "2" );
		assertTrue(term.isAbsTheSame(term.copy()));
	}

	public void testCopySymbol() throws ExpressionParserException{
		ExpressionParser parser = new ExpressionParser();
			
		Term term = parser.parseText( "x" );
		assertTrue(term.isAbsTheSame(term.copy()));
	}

	public void testCopySum() throws ExpressionParserException{
		ExpressionParser parser = new ExpressionParser();
			
		Term term = parser.parseText( "2+x" );
		assertTrue(term.isAbsTheSame(term.copy()));
	}

	public void testCopyProduct() throws ExpressionParserException{
		ExpressionParser parser = new ExpressionParser();
			
		Term term = parser.parseText( "2*x" );
		assertTrue(term.isAbsTheSame(term.copy()));
	}

	public void testCopyFraction() throws ExpressionParserException{
		ExpressionParser parser = new ExpressionParser();
			
		Term term = parser.parseText( "2/x" );
		assertTrue(term.isAbsTheSame(term.copy()));
	}

	public void testCopyExponentiation() throws ExpressionParserException{
		ExpressionParser parser = new ExpressionParser();
			
		Term term = parser.parseText( "2^x" );
		assertTrue(term.isAbsTheSame(term.copy()));
	}

	public void testEquals() throws ExpressionParserException{
		ExpressionParser parser = new ExpressionParser();
			
		Term termA = parser.parseText( "2^x" );
		Term termB = parser.parseText( "2^x" );
		assertTrue(termA.equals(termB));
	}

	public void testRealNumber() throws ExpressionParserException{
		ExpressionParser parser = new ExpressionParser();
			
		Term termA = parser.parseText( "2^3" );
		Term termB = parser.parseText( "(-2)$2" );
		
		assertTrue(termA.isRealNumber());
		assertFalse(termB.isRealNumber());
	}

}
